import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rider/event/show_operator_info_event.dart';
import 'package:flutter_rider/generated/r.dart';
import 'package:flutter_rider/main.dart';
import 'package:flutter_rider/main/widgets/ext/u_layout.dart';
import 'package:flutter_rider/main/widgets/ext/u_text.dart';
import 'package:flutter_rider/main/widgets/ui_constant.dart';
import 'package:flutter_rider/module/mine/models/operator_model.dart';
import 'package:flutter_rider/utils/screen_fit.dart';
import 'package:flutter_svg/svg.dart';

class PopOperatorInfo extends StatefulWidget {
  final OperatorModel model;

  const PopOperatorInfo(this.model, {Key? key}) : super(key: key);

  @override
  State createState() => PopOperatorInfoState();
}

class PopOperatorInfoState extends State<PopOperatorInfo> {
  @override
  void initState() {
    super.initState();
    Future.delayed(const Duration(milliseconds: 100), () {
      eventBus.fire(ShowPopOperatorInfoEvent(true)); //延迟下，等上次的弹框 dispose 在 发出新的事件
    });
  }

  @override
  void dispose() {
    super.dispose();
    eventBus.fire(ShowPopOperatorInfoEvent(false));
  }

  @override
  Widget build(BuildContext context) {
    return IntrinsicHeight(
        child: SafeArea(
            child: Container(
      padding: EdgeInsets.only(
          top: 8.rpx, left: 16.rpx, right: 16.rpx, bottom: 16.rpx),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.vertical(top: Radius.circular(8.rpx)),
      ),
      child: Column(
        children: [
          8.hspace,
          Container(
            width: 36.rpx,
            height: 5.rpx,
            decoration: BoxDecoration(
              color: Colors.black.withOpacity(0.26),
              borderRadius: BorderRadius.circular(2.rpx),
            ),
          ),
          8.hspace,
          Row(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                24.wspace,
                Expanded(
                    child: Container(
                  alignment: Alignment.center,
                  child: UText.get("操作员详情", Colors.black, 20.rpx,
                      fw: FontWeight.bold),
                )),
                4.wspace,
                InkWell(
                  child: SvgPicture.asset(R.image_close,
                      width: 24.rpx, height: 24.rpx),
                  onTap: _closeClick,
                ),
              ]),
          24.hspace,
          Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
            UText.get("姓名", UIColor.color_t3, 16.rpx),
            16.wspace,
            UText.get(widget.model.name, UIColor.color_t16, 16.rpx).expand,
          ]),
          16.hspace,
          Row(children: [
            UText.get("电话", UIColor.color_t3, 16.rpx),
            16.wspace,
            UText.get(widget.model.mobile, UIColor.color_primary, 16.rpx),
          ]),
          16.hspace,
          Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
            UText.get("位置", UIColor.color_t3, 16.rpx),
            16.wspace,
            UText.get(widget.model.station_name, UIColor.color_t16, 16.rpx)
                .expand,
            UText.get("距离 ${widget.model.distance.toStringAsFixed(2)} 米",
                UIColor.color_t17, 16.rpx),
          ]),
          ScreenUtil.getInstance().bottomBarHeight.hspace
        ],
      ),
    )));
  }

  _closeClick() {
    Navigator.of(context).pop();
  }
}
